#ifndef YUVPLAYER_H
#define YUVPLAYER_H

#include <QWidget>
#include <SDL2/SDL.h>
#include <QFile>
#include <QDebug>
extern "C" {

    #include <libavutil/imgutils.h>

}

struct YUVSpec{

    int width;
    int height;
    AVPixelFormat pixelFmt;
    int framerate;
    char* yuvPath;
};


class YUVPlayer : public QWidget
{
    Q_OBJECT
public:

    enum State{
        Stop,
       Playing,
       Pause
    };

    explicit YUVPlayer(YUVSpec &yuvSpec, QWidget *parent = nullptr);
    ~YUVPlayer();
    void start();
    void stop();
    void pause();
    bool isPlay();
signals:

private:
    SDL_Window* window = nullptr;
    SDL_Renderer* render = nullptr;
    SDL_Texture* texture = nullptr;
    QFile* file = nullptr;
    YUVSpec yuvSpec;
    int timer = 0;
    int imageBufferSize = 0;

    YUVPlayer::State state = YUVPlayer::Stop;
    char* imageBuffer = nullptr;
    void timerEvent(QTimerEvent* event);

};

#endif // YUVPLAYER_H
